'use strict'

angular.module('myApp.viewTaskDetail', [])

    .controller('ViewTaskDetail', ['$rootScope', '$scope', '$routeParams', '$location', function ($rootScope, $scope, $routeParams, $location) {
        $scope.taskId = $routeParams.taskId;
        $scope.taskContent = "";
        $scope.creationTime = "";

        for (var i = 0; i < $rootScope.tasks.length; ++i) {
            if ($rootScope.tasks[i].task_id == $scope.taskId) {
                $scope.taskContent = $rootScope.tasks[i].task_content;
                $scope.creationTime = $rootScope.tasks[i].creation_time;
                break;
            }
        }

        $scope.onDeleteTask = function () {
            for (var i = 0; i < $rootScope.tasks.length; ++i) {
                if ($rootScope.tasks[i].task_id == $scope.taskId) {
                    $rootScope.tasks.splice(i, 1);
                    break;
                }
            }
            
            $location.path('/' + $routeParams.userName + '/tasklist');
        };
    }]);